package com.bridge.bridge_wd.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bridge.bridge_wd.R;


/**
 * @ClassName PictureSelectDialog
 * @Description TODO图片选择 dialog
 * @Author biekangdong
 * @CreateDate 2021/4/8 10:12
 * @Version 1.0
 * @UpdateDate 2021/4/8 10:12
 * @UpdateRemark 更新说明
 */
public class PictureSelectDialog extends Dialog {
    private DialogViewListener listener;
    private Activity mContext;

    private TextView tvSelect;
    private TextView tvCamera;
    private TextView tvCancel;

   

    public interface DialogViewListener {
        void cameraClick();
        void selectClick();
    }

    public void setDialogViewListener(DialogViewListener listener) {
        this.listener = listener;
    }

    public PictureSelectDialog(Activity context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_picture_select, null);
        setContentView(view);
        //获取当前Activity所在的窗体
        Window dialogWindow = getWindow();
        //设置Dialog从窗体中间弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        dialogWindow.setBackgroundDrawableResource(R.color.home_tm);
        //解决弹出被底部导航栏遮挡问题
        dialogWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //消除边距
        dialogWindow.getDecorView().setPadding(12, 0, 12, 20);
        //设置Dialog点击外部消失
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        lp.width = mContext.getResources().getDisplayMetrics().widthPixels / 10 * 9;
        lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
        //将属性设置给窗体
        dialogWindow.setAttributes(lp);
        dialogWindow.setWindowAnimations(R.style.pop_animation_bottom);

        tvSelect = (TextView) findViewById(R.id.tv_select);
        tvCamera = (TextView) findViewById(R.id.tv_camera);
        tvCancel = (TextView) findViewById(R.id.tv_cancel);

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });
        tvCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener!=null){
                    listener.cameraClick();
                }
                cancel();
            }
        });
        tvSelect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(listener!=null){
                    listener.selectClick();
                }
                cancel();
            }
        });
    }



    @Override
    public void dismiss() {
        super.dismiss();
    }

}
